<template>
  <a-modal
    :title="title"
    :width="460"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="取消"
    okText="保存">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="类型名称"
          hasFeedback >
          <a-input placeholder="请输入收费类型名称" v-model="category_name"/>
        </a-form-item>

<!--        <a-form-item-->
<!--          :labelCol="labelCol"-->
<!--          :wrapperCol="wrapperCol"-->
<!--          label="编号"-->
<!--          hasFeedback >-->
<!--          <a-input placeholder="请输入收费类型编号" v-model="category_code"/>-->
<!--        </a-form-item>-->

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="序号"
          hasFeedback >
          <a-input placeholder="请输入收费类型排序" v-model="category_numbers"/>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注"
          hasFeedback >
          <a-textarea placeholder="请输入备注信息" v-model="remark" rows="4"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction, postAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import JImageUpload from '../../../components/jeecg/JImageUpload'
  import Qs from "qs";

  export default {
    name: "JeecgDemoModal",
    components: {
      JImageUpload
    },
    data () {
      return {
        category_name:'',
        category_code:'',
        category_numbers:'0',
        remark:'',
        categorydetail:[],
        topId:'',//上级id
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        couponList: [
          {
            id: '4',
            name: '式样'
          },
          {
            id: '5',
            name: '紧急指数'
          },
          {
            id: '6',
            name: '改款打样'
          }
        ],
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          fileUpload: window._CONFIG['domianURL'] + "/sys/common/upload",
          query_detail:"/admin/parameter/query_syspriceByid",
          add: "/admin/parameter/add_test_addpriceinfo",
          edit: "/admin/parameter/update_test_addpriceinfo"
        },
      }
    },
    computed: {
      uploadAction: function() {
        return this.url.fileUpload;
      }
    },
    created () {
    },
    methods: {
      edit (record) {
        this.category_numbers='0',
        this.category_name='';
        this.category_code='';
        this.remark='';
        this.model = Object.assign({}, record);
        this.visible = true;//开启弹框
        if(record=="0"){
          this.title="添加收费类型"
          this.topId = '';
        }else {
          this.title="编辑收费类型"
          this.show_categorydetail(record);
          this.topId = record;
        }
      },
      show_categorydetail(id) {
        // alert(id)
        let params = {dinghzi_id:id};
        getAction(this.url.query_detail,params).then((res)=>{
          // console.info(res);
          if(res.success){
            this.categorydetail = res.result;
            this.category_name=this.categorydetail.premiumItem;
            this.category_code=this.categorydetail.premiumCode;
            this.remark=this.categorydetail.remark;
            this.category_numbers=this.categorydetail.numbers;
          }else {
            this.$message.error("查询失败");
          }
        });
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if(this.category_name==null || this.category_name==''){
            this.$message.warning("请输入收费类型名称");
            return;
          }else if(this.category_numbers==='' || this.category_numbers===null){
            this.$message.warning("请输入收费类型排序");
            return;
          }
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            let params = '';
            if(this.topId != null && this.topId != ''){
              httpurl+=this.url.edit;
              method = 'put';
              params = {premiumItem:this.category_name,remark:this.remark,
                numbers:this.category_numbers,type:0,id:this.topId}
            }else{
              httpurl+=this.url.add;
              method = 'post';
              params = {premiumItem:this.category_name,remark:this.remark,
                numbers:this.category_numbers,categoryId:this.$route.query.category_id,type:0,
                partentId:'0',isTop:'1'}
            }
            httpAction(httpurl,params,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>

<style scoped>

</style>